// pages/information/information.js
import { getAllConsultants } from '../../api/query'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    consultantsList: [],
    query: {
      channelId: 409,
      pageNo: 1,
      pageSize: 5
    },
    loading: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData()
  },
  //获取所有咨询师数据
  async getData() {
    this.setData({
      loading: 1
    })
    let result = await getAllConsultants(this.data.query)
    if (!result.data.data.list.length) {
      this.setData({
        loading: 2
      })
    }
    this.setData({
      consultantsList: [...this.data.consultantsList, ...result.data.data.list]
    })
  },
  //滑动到底部
  onReachBottom() {
    this.setData({
      'query.pageNo': this.data.query.pageNo + 1
    })
    if(this.data.loading != 2){
      this.getData()
    }
  },
  //跳转至详情页
  goDetail(e){
    wx.navigateTo({
      url: `../../query/pages/query/query?id=${e.currentTarget.dataset.id}`,
    })
  },
  //跳转至筛选
  goSearch(){
    wx.navigateTo({
      url: '../../query/pages/search/search',
    })
  }
})